var wrappedCBs = document.querySelectorAll('.wrap');

for (var i = 0; i < wrappedCBs.length; (i = i + 1)) {
    wrappedCBs[i].onclick = cbClickHandler;
}

function cbClickHandler(e) {
    alert(this.id);
    return;
    follow(this.id);

}

function report(str) {
    document.querySelector('#report').innerHTML = str;
}
function follow(id) {
    $.ajax({
        url: "http://localhost/fchic.vn/user/follow?id=" + id,
        type: 'GET',
        success: function(data) {
            follow_success(id);
        }
    });
}
function follow_success(id) {
    var relatedCheckBox = document.querySelector('#' + this.id);
    relatedCheckBox.checked = !relatedCheckBox.checked;
    this.className = 'wrap ' + (relatedCheckBox.checked ? 'checked' : 'unchecked');
    // report checkstate
    report('#' + this.id.substr(0, this.id.indexOf('_')) + ' checked state:  ' + relatedCheckBox.checked);
}